package com.darwin.darwinUI.controls
{
	import com.darwin.darwinUI.containers.Box;
	import com.darwin.darwinUI.containers.Layer;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.DarwinFont;
	import com.darwin.darwinUI.uiconst.LocateType;
	import com.darwin.darwinUI.uiconst.UIAlign;
	
	import flash.display.DisplayObject;

	/**
	 * 数值选择器 包括输入文本/增加 减少调整按钮 可通过设置布局来调整按钮位置 </br>
	 * 数值变化时会派发 UIEvent.UI_CHANGE事件</br>
	 * 可直接获取组件当前选择的数值
	 * @author vanCopper
	 * 
	 */	
	public class NumericStepper extends UIComponent
	{
		//TODO 文字 合并拆开  文本与按钮间距  按钮间距 
		//TODO 最大值按钮 最小值按钮
		private var _prevDisplay:DisplayObject;
		private var _prevSkin:String;
		private var _nextDisplay:DisplayObject;
		private var _nextSkin:String;
		/**
		 * 数值框 
		 */		
		private var _numInput:TextInput;
		private var _currentValue:int;
		
		private var _prevBtn:Button;
		private var _nextBtn:Button;
		
		private var _min:int = 0;
		private var _max:int = 0;
		
		private var _container:Layer;
		
		private var _distance:Number = 10;
		
		
		
		public function NumericStepper(min:int = 0,max:int = 100)
		{
			super();
			this.min = min;
			this.max = max;
		}
		
		override protected function initUIComponent():void
		{
			super.initUIComponent();
			
			_container = new Layer();
			addChild(_container);
			
			_prevBtn = new Button();
			_prevBtn.backgroundAuto = true;
			_container.addItem(_prevBtn);
			
			_numInput = new TextInput();
			_numInput.horizontalLocate = LocateType.FOLLOW_AFTER;
//			_numInput.border = false;
			_numInput.border = true;
			_numInput.horizontalFollowObject = _prevBtn;
			_numInput.offsetX = distance; 
			_container.addItem(_numInput);

			_nextBtn = new Button();
			_nextBtn.backgroundAuto = true;
			_nextBtn.horizontalLocate = LocateType.FOLLOW_AFTER;
			_nextBtn.horizontalFollowObject = _numInput;
			_nextBtn.offsetX = distance;
			_container.addItem(_nextBtn);
		}
		
		
		
		override public function set width(value:Number):void
		{
			super.width = value;
			_container.width = value;
			super.invalidate();
		}
		
		override public function set height(value:Number):void
		{
			super.height = value;
			_container.height = value;
			super.invalidate();
		}

		public function set textInputFont(value:DarwinFont):void
		{
			if(_numInput && value)
			{
				_numInput.font = value;
			}
		}
		/**
		 * 减少按钮 
		 */
		public function get prevDisplay():DisplayObject
		{
			return _prevDisplay;
		}

		private var _prevChange:Boolean = false;
		/**
		 * @private
		 */
		public function set prevDisplay(value:DisplayObject):void
		{
			_prevDisplay = value;
			_prevBtn.background = _prevDisplay;
			_prevChange = true;
			super.invalidate();
		}

		/**
		 * 减少按钮皮肤
		 */
		public function get prevSkin():String
		{
			return _prevSkin;
		}

		/**
		 * @private
		 */
		public function set prevSkin(value:String):void
		{
			_prevSkin = value;
			_prevBtn.backgroundSkin = _prevSkin;
		}

		/**
		 * 增加按钮 
		 */
		public function get nextDisplay():DisplayObject
		{
			return _nextDisplay;
		}

		private var _nextChange:Boolean = false;
		/**
		 * @private
		 */
		public function set nextDisplay(value:DisplayObject):void
		{
			_nextDisplay = value;
			_nextBtn.background = _nextDisplay;
			_nextChange = true;
			super.invalidate();
		}

		/**
		 * 增加按钮皮肤 
		 */
		public function get nextSkin():String
		{
			return _nextSkin;
		}

		/**
		 * @private
		 */
		public function set nextSkin(value:String):void
		{
			_nextSkin = value;
			_nextBtn.backgroundSkin = _nextSkin;
		}

		/**
		 * 当前数值 
		 */
		public function get currentValue():int
		{
			return _currentValue;
		}

		private var _valueChange:Boolean = false;
		/**
		 * @private
		 */
		public function set currentValue(value:int):void
		{
			_currentValue = value;
			if(value >= min && value <= max)
			{
				_valueChange = true;
				_numInput.text = ""+value;
			}
			super.invalidate();
		}
		
		override protected function refresh():void
		{
			super.refresh();
			if(_valueChange)
			{
				
			}
			//TODO 更新布局
		}

		/**
		 * 数值选择器 最小值 
		 */
		public function get min():int
		{
			return _min;
		}

		/**
		 * @private
		 */
		public function set min(value:int):void
		{
			_min = value;
		}

		/**
		 * 数值选择器 最大值 
		 */
		public function get max():int
		{
			return _max;
		}

		/**
		 * @private
		 */
		public function set max(value:int):void
		{
			_max = value;
		}

		/**
		 * 按钮与文本的间距 
		 */
		public function get distance():Number
		{
			return _distance;
		}

		/**
		 * @private
		 */
		public function set distance(value:Number):void
		{
			_distance = value;
		}


	}
}